import { DEVICE_STATUS_NUMBER, BUTTON_FEE_TYPE } from '@/views/ops/common/config'
import { request } from '@/api/service'
import XEUtils from 'xe-utils'
import {urlPrefix as deptPrefix} from "@/views/system/dept/api";

export const crudOptions = (vm) => {
  return {

    pageOptions: {
      compact: true,
      export: {
        local: true // 本地导出，false为服务端导出
      }
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false,
      treeConfig: { // 树形数据配置
        children: 'children',
        hasChild: 'hasChildren',
        expandAll: true
      }
    },
    rowHandle: {
      width: 140,
      view: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '35%'
    },
    columns: [{
      title: '关键词',
      key: 'search',
      show: false,
      disabled: true,
      search: {
        disabled: false
      },
      form: {
        disabled: true,
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入关键词'
        }
      },
      view: { // 查看对话框组件的单独配置
        disabled: true
      }
    },
    {
      title: 'ID',
      key: 'id',
      show: false,
      disabled: true,
      width: 90,
      form: {
        disabled: true
      }
    },
    {
      title: '设备名称',
      key: 'devices_name',
      sortable: true,
      treeNode: true,
      search: {
        disabled: true,
        component: {
          props: {
            clearable: true
          }
        }
      },
      type: 'input',
      form: {
        // editDisabled: true,
        value: '笔记本电脑',
        rules: [ // 表单校验规则
          { required: true, message: '名称必填项' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入名称'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '设备编码',
      key: 'devices_num',
      sortable: true,

      search: {
        disabled: false,
        component: {
          props: {
            clearable: true
          }
        }
      },

      type: 'input',
      form: {
        rules: [ // 表单校验规则
          { required: true, message: '显示值必填项' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入设备编码'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '设备型号',
      key: 'devices_type',
      sortable: true,

      search: {
        disabled: true,
        component: {
          props: {
            clearable: true
          }
        }
      },

      type: 'input',
      form: {
        value: '输入设备型号',
        rules: [ // 表单校验规则
          { required: true, message: '型号' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入设备型号'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },

    {
      title: '设备用途',
      key: 'devices_usages',
      sortable: true,

      search: {
        disabled: true,
        component: {
          props: {
            clearable: true
          }
        }
      },

      type: 'input',
      form: {
        value: '请输入设备用途',
        rules: [ // 表单校验规则
          { required: false, message: '用途' }
        ],
        component: {
          props: {
            clearable: true
          },
          placeholder: '请输入设备用途'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '配置',
      key: 'devices_configuration',
      sortable: true,

      search: {
        disabled: true,
        component: {
          props: {
            clearable: true
          }
        }
      },

      type: 'input',
      form: {
        value: 'AOC 238LM00023',
        rules: [ // 表单校验规则
          { required: false, message: '实际值必填项' }
        ],
        component: {
          props: {
            clearable: true,
            type: 'textarea'
          },
          placeholder: '请输入配置信息'
        },
        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '状态',
      key: 'status',
      sortable: true,
      search: {
        disabled: false
      },

      type: 'radio',
      dict: {
        data: DEVICE_STATUS_NUMBER
      },
      form: {
        value: 1,
        component: {}
      }
    },
    {
      title: '使用者',
      key: 'devices_ownner',
      search: {
        disabled: false
      },
      type: 'select',
      dict: {
        url: '/api/system/user/?limit=999',
        value: 'id', // 数据字典中value字段的属性名
        label: 'name', // 数据字典中label字段的属性名
        getData: (url) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            console.log(ret.data.data)
            return ret.data.data
          })
        }
      },
      form: {
        component: {
          show: true,
          clearable: true,
          filterable: true
        },
        helper: {
          render () {
            return (< el-alert title="若无对应人员，请前往系统管理-用户管理添加" type="info"/>
            )
          }
        }
      }
    },
    {
      title: '费用类型',
      key: 'fee_type',
      sortable: true,
      search: {
        disabled: false
      },

      type: 'select',
      dict: {
        data: BUTTON_FEE_TYPE
      },
      form: {
        value: 1,
        component: {}
      }
    },
    {
      title: '费用',
      key: 'fee_number',
      sortable: true,

      search: {
        disabled: true,
        component: {
          props: {
            clearable: true
          }
        }
      },

      type: 'number',
      form: {
        value: '0'
      }
    },
    {
      title: '设备归属部门',
      key: 'devices_dept',
      search: {
        disabled: true
      },
      minWidth: 140,
      type: 'tree-selector',
      dict: {
        cache: false,
        isTree: true,
        url: '/api/system/dept/?limit=999&status=1',
        value: 'id', // 数据字典中value字段的属性名
        label: 'name' // 数据字典中label字段的属性名
      },
      form: {
        rules: [ // 表单校验规则
          {
            required: true,
            message: '必填项'
          }
        ],
        itemProps: {
          class: { yxtInput: true }
        },
        component: {
          span: 12,
          pagination: true,
          props: { multiple: false }
        }
      }
    }
    ].concat(vm.commonEndColumns({ show_dept_belong_id: true, show_dept_when_add: false, show_datetime: false })),
    formGroup: {
      type: 'collapse', // tab
      accordion: false,
      groups: {
        base: {
          title: '基本设置',
          icon: 'el-icon-goods',
          columns: ['devices_name', 'devices_num', 'devices_type', 'status', 'devices_ownner']
        },
        info: {
          title: '详情',
          collapsed: true,
          icon: 'el-icon-warning-outline',
          columns: ['fee_type', 'fee_number', 'devices_usages', 'devices_configuration', 'description', 'dept_belong_id', 'devices_dept']
        }
      }
    }
  }
}
